import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { SPetChallengeLog } from "../../../../../Message/Game/SPetChallengeLog";
import { Language } from "../../../../../extend/language/Language";
import { DateParser } from "../../../../common/tools/DateParser";
import { PlayerUtil } from "../../common/util/PlayerUtil";
import { PetCpnRewardUtil } from "./info/PetCpnRewardUtil";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
//class PetCpnLogCellRenderer
    
    export  class PetCpnLogCellRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            this._log = arg1 as SPetChallengeLog;
            this.updateByLog(this._log);
            return;
        }

        public updateByLog(arg1: SPetChallengeLog): void
        {
            var loc1="";
            if (arg1) 
            {
                if (arg1.success) 
                {
                    loc1 = Language.getString(54700);
                }
                else 
                {
                    loc1 = Language.getString(54701);
                }
                loc1 = loc1 + DateParser.parse(arg1.logDt, "[MM-dd hh: mm]");
                if (arg1.challenge) 
                {
                    loc1 = loc1 + Language.getStringByParam(54685, PlayerUtil.getProxyAndNameByEntityIdAndName(arg1.entityId, arg1.playerName));
                    if (arg1.success) 
                    {
                        loc1 = loc1 + Language.getString(54686);
                        if (arg1.rewards.length > 0) 
                        {
                            loc1 = loc1 + (Language.getString(54687) + PetCpnRewardUtil.getStrByRewardArray(arg1.rewards));
                        }
                    }
                    else 
                    {
                        loc1 = loc1 + Language.getString(54688);
                    }
                }
                else 
                {
                    loc1 = loc1 + Language.getStringByParam(54689, PlayerUtil.getProxyAndNameByEntityIdAndName(arg1.entityId, arg1.playerName));
                    if (arg1.success) 
                    {
                        loc1 = loc1 + Language.getString(54690);
                    }
                    else 
                    {
                        loc1 = loc1 + Language.getString(54691);
                        if (arg1.rewards.length > 0) 
                        {
                            loc1 = loc1 + (Language.getString(54692) + PetCpnRewardUtil.getStrByRewardArray(arg1.rewards));
                        }
                    }
                }
            }
            this._logTxt.htmlText = loc1;
            return;
        }

        /* internal  */init(): void
        {
            LoaderHelp.addResCallBack(ResFileConst.PetCpn, this.onLoadedHandler);
            this._logTxt = ObjCreate.createTextField("", 22, 0, 480, 20, this);
            this._logTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._logTxt.wordWrap = true;
            this._logTxt.multiline = true;
            return;
        }

        /* internal  */onLoadedHandler(): void
        {
            ObjCreate.createBitmap(ImagesConst.PetCpnAttack, 0, 0, this);
            return;
        }

        /* internal */ /* var */_logTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_log: SPetChallengeLog;
    }
